package com.hmall.search.web;

import com.hmall.common.PageDto;
import com.hmall.search.dto.SearchDto;
import com.hmall.search.pojo.ItemDoc;
import com.hmall.search.service.ISearchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("search")
public class SearchController {

    @Autowired
    private ISearchService searchService;

    /**
     * 1. 条件搜索
     * @param searchDto 条件
     * @return 结果
     */
    @PostMapping("list")
    public PageDto<ItemDoc> search(@RequestBody SearchDto searchDto) throws Exception {
        return searchService.search(searchDto);
    }

    /**
     * 2. 获取筛选条件
     * @param searchDto 请求参数对象
     * @return
     */
    @PostMapping("filters")
    public Map<String, List<String>> filters(@RequestBody SearchDto searchDto) throws Exception {
        return searchService.getFilters(searchDto);
    }

    /**
     * 3. 关键词推荐
     *
     * @param key 关键词前缀
     * @return 关键词集合
     */
    @GetMapping("/suggestion")
    List<String> suggestion(String key) throws Exception{
        return searchService.getSuggestion(key);
    }

}
